// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import Vuex from 'vuex'

Vue.use(Vuex)
const store = new Vuex.Store({
  state: {
    is_login: 0
  },
  mutations: {
    changeLogin(state,data){
        state.is_login = data
    }
  }
})

//console.log("333333333333333 ", is_auth)
//if(g_is_auth) {
//    store.commit('changeLogin',g_is_auth)
//}
global.g_store=store
// todo // export default store

router.beforeEach((to, from, next) => {
    if(to.matched.some( m => m.meta.auth)){
        if(g_store.state.is_login== 1) { // 已经登陆
            next()   // 正常跳转到你设置好的页面
        }
        else{
            // 未登录则跳转到登陆界面，query:{ Rurl: to.fullPath}表示把当前路由信息传递过去方便登录后跳转回来；
            next({path:'/login',query:{Rurl: to.fullPath}})
 　　　 }
    }
    else
    {
　　　　next()
    }
})

global.router=router

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
